﻿#ifndef __SS_XML_READER_H__
#define __SS_XML_READER_H__
#include "./tinyxml/tinyxml.h"
//#include <vector>
//#include <string>

namespace StarSeeker
{

class ssTinyxmlExpand
{
public:
	ssTinyxmlExpand(void);
	~ssTinyxmlExpand(void);
	//
	void Clear();
	//从文件读入
	bool LoadXmlFromFile(const char * pPath, TiXmlEncoding type=TIXML_ENCODING_UNKNOWN);
	//从内存读入
	bool LoadXmlFromString(const char * str, TiXmlEncoding type=TIXML_ENCODING_UNKNOWN);

	//获取子节点
	TiXmlElement * GetChildNodeByName(char * pName);
	//获取第一个子节点
	TiXmlElement * GetFristChildNode();
	//按顺序获取下一个子节点
	TiXmlElement * GetNextChildNode();
	//循环获取子节点
	TiXmlElement * GetChildNode();
	//指定节点
	void SetCurrentNode(TiXmlElement * pElement);
	//回到根节点
	void BackToRoot();
	//获取根节点
	TiXmlElement * GetRoot() {return m_pRootNode;}

	//获取元素行第一个属性
	TiXmlAttribute * GetFristAttribute(TiXmlElement * pElement=0);
	//按顺序获取下一个属性
	TiXmlAttribute * GetNextAttribute();
	//按顺序获取元素
	TiXmlAttribute * GetAttribute(TiXmlElement * pElement=0);


	const char* GetElementName(TiXmlElement * pElement=0);
	const char* GetElementText(TiXmlElement * pElement=0);
	const char* GetAttributeName();
	int GetIntAttribute();
	double GetDoubleAttribute();
	const char* GetStringAttribute();

private:
	TiXmlDocument	*	m_pXmlDoc;
	TiXmlElement	*	m_pRootNode;
	TiXmlElement	*	m_pCurrentNode;
	bool				m_firstLoop;
	TiXmlAttribute	*	m_pAttribute; 
	TiXmlElement	*	m_pSubElement;
};

}
#endif

//<RootNode>
//	<ChildNode>
//		<ChildElement a='' b='' c=''/>
//	</ChildNode>
//</RootNode>

//inline void ConvertUtf8ToGBK(std::string & strUtf8) 
//{
//	int len = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, NULL, 0);
//	unsigned short * wszGBK = new unsigned short[len+1];
//	memset(wszGBK, 0, len * 2 + 2);
//	MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, (LPWSTR)wszGBK, len);
//
//	len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
//	char *szGBK = new char[len + 1];
//	memset(szGBK, 0, len + 1);
//	WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wszGBK, -1, szGBK, len, NULL,NULL);
//
//	strUtf8 = szGBK;
//	delete[] szGBK;
//	delete[] wszGBK;
//}

//inline  void ConvertGBKToUtf8(std::string & strGBK)
//{
//	int len = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
//	unsigned short * wszUtf8 = new unsigned short[len+1];
//	memset(wszUtf8, 0, len * 2 + 2);
//	MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, (LPWSTR)wszUtf8, len);
//
//	len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, NULL, 0, NULL, NULL);
//	char *szUtf8=new char[len + 1];
//	memset(szUtf8, 0, len + 1);
//	WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, szUtf8, len, NULL,NULL);
//
//	strGBK = szUtf8;
//	delete[] szUtf8;
//	delete[] wszUtf8;
//}
